<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class ActivityPostRequest extends Request
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        $data = Request::all();
        if (isset($data['id'])) {
            $rules['id'] = 'required|numeric';
        }
//        $rules['organizer'] = 'required';
//        $rules['organizer_url'] = 'required|url';
        if (!empty($data['views'])) {
            $rules['views'] = 'numeric';
        }
//        $rules['apply_start_time'] = 'required|date';
        $rules['apply_end_time'] = 'required|date';
        $rules['subject'] = 'required';
        $rules['begin_time'] = 'required|date';
        $rules['end_time'] = 'required|date';
        $rules['content'] = 'required';
//        $rules['photo'] = 'required';
//        $rules['bg_img'] = 'required';
        $rules['haibao'] = 'required';
//        $rules['path_url'] = 'required|url';
//        $rules['video_url'] = 'required|url';
//        $rules['app_video_url'] = 'required|url';
//        $rules['video_photo'] = 'required';
        $rules['live_url'] = 'sometimes|numeric';
//        $rules['times'] = 'required';
//        $rules['wx_photo'] = 'required';
        $rules['type'] = 'required';
        $rules['zone_id'] = 'required|numeric';
        $rules['uid'] = 'required|numeric';
        if ($data['is_assemble'] == 1) {
            $rules['assemble_end_time'] = 'required|date';
        }

        $rules['maker_id'] = 'sometimes|numeric';

        return $rules;
//        return array();
    }

    public function attributes()
    {
        $attributes = array(
            'id'                => '活动id',
            'organizer'         => '主办方',
            'organizer_url'     => '主办方网址',
            'views'             => '浏览量',
            'apply_start_time'  => '报名开始时间',
            'apply_end_time'    => '报名结束时间',
            'subject'           => '标题',
            'begin_time'        => '活动开始时间',
            'end_time'          => '活动结束日期',
            'content'           => '内容',
            'photo'             => '图片',
            'bg_img'            => '大图',
            'haibao'            => '海报',
            'path_url'          => '现场报道地址',
            'video_url'         => '整场视频地址',
            'app_video_url'     => 'app整场视频地址',
            'live_url'          => '直播地址',
            'times'             => '时长',
            'wx_photo'          => '微信报名活动图片',
            'assemble_end_time' => '招集结束时间',
            'type'              => '活动类型',
            'zone_id'           => '地区id',
            'uid'               => '活动拥有人',
            'maker_id'          => '活动主办方（创客空间）',
        );

        return $attributes;
//        return array();
    }

    public function messages()
    {
        $messages = [
            'required' => ':attribute为必填选项',
            'numeric'  => ':attribute必须为数字',
            'url'      => ':attribute必须为合乎规范的url地址',
            'date'     => ':attribute必须为日期',
        ];

        return $messages;
    }
}
